


<template>
    <div class="model-form">
        <el-page-header @back="goBack" content="增加优惠券">
        </el-page-header>
        <div class="model-content">
            <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
                <el-row :gutter="10">
    <el-col :span="20">
            <el-form-item label="名称"  prop="name">
        <el-input v-model="form.name" name="name">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="封面"  prop="logo">
        <avatar v-model="form.logo"></avatar>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="面额"  prop="money">
        <el-input v-model="form.money" name="money">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="使用门槛"  prop="minPrice">
        <el-input-number v-model="form.minPrice" name="minPrice" type="textarea" :min="0" :max="99999999.99"  style="width: 100%;" ></el-input-number>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="每人限领"  prop="limitNum">
        <el-input-number v-model="form.limitNum" name="limitNum" :min="0" :max="9999999" style="width: 100%;"></el-input-number>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="发放开始时间"  prop="sendBeginTime">
        <el-date-picker v-model="form.sendBeginTime" type="datetime" value-format="YYYY-MM-DD HH:mm"
                        placeholder="选择日期">
        </el-date-picker>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="发放截止时间"  prop="sendEndTime">
        <el-date-picker v-model="form.sendEndTime" type="datetime" value-format="YYYY-MM-DD HH:mm"
                        placeholder="选择日期">
        </el-date-picker>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="优惠券开始时间"  prop="useBeginTime">
        <el-date-picker v-model="form.useBeginTime" type="datetime" value-format="YYYY-MM-DD HH:mm"
                        placeholder="选择日期">
        </el-date-picker>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="优惠券截止时间"  prop="useEndTime">
        <el-date-picker v-model="form.useEndTime" type="datetime" value-format="YYYY-MM-DD HH:mm"
                        placeholder="选择日期">
        </el-date-picker>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="固定天数"  prop="useDay">
        <el-input-number v-model="form.useDay" name="useDay" :min="0" :max="9999999" style="width: 100%;"></el-input-number>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="卡券库存"  prop="stock">
        <el-input-number v-model="form.stock" name="stock" :min="0" :max="9999999" style="width: 100%;"></el-input-number>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="使用说明"  prop="note">
        <el-input v-model="form.note" name="note" type="textarea"></el-input>
            </el-form-item>

    </el-col>
    <el-col :span="12">
            <el-form-item label="添加时间"  prop="addDate">
        <el-input v-model="form.addDate" name="addDate">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="20">
            <el-form-item label="活动范围"  prop="couponScope">
        <el-input v-model="form.couponScope" name="couponScope">
        </el-input>
            </el-form-item>

    </el-col>

                    <el-col :span="22">
                        <el-form-item>
                            <el-button @click="goBack">取消</el-button>
                            <el-button type="primary" @click="add">确定</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
    import common from "@/mixins/common.js";
    import {ElLoading} from "element-plus";

    import avatar from "@/components/avatar.vue";

    export default {
        name: "ShopCouponRule_add",
        mixins: [common],
        components: {avatar},
        data() {
            return {
                form: {
                    name: '',
                    logo: '',
                    money: '',
                    minPrice: '',
                    limitNum: '',
                    sendBeginTime: '',
                    sendEndTime: '',
                    useBeginTime: '',
                    useEndTime: '',
                    useDay: '',
                    stock: '',
                    note: '',
                    addDate: '',
                    couponScope: ''                },
                rules: {
                    name: [
                        {required: true, message: '请输入名称', trigger: 'blur'}
                    ],
                    money: [
                        {required: true, message: '请输入面额', trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            async add() {
                try {
                    let valid = await this.$refs["ruleForm"].validate();
                    if (!valid) {
                        return;
                    }
                } catch (e) {
                    return;
                }

                await this.addData();
            },
            async addData() {
                let data = this.form;
                const loading = ElLoading.service({
                    lock: true,
                    text: '数据处理中',
                    background: 'rgba(0, 0, 0, 0.7)',
                })

                let res = await this.$http.form("/shopCouponRule/create", data);

                loading.close();

                if (res.code !== 200) {
                    this.$message.error(res.msg);
                    return;
                }

                this.$message({
                    message: '添加数据成功',
                    type: 'success'
                });
                this.$router.go(-1);
            },

        },
        mounted() {
        }
    }

</script>

<style scoped>
</style>